/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean;

import entity.CustomerEntity;
import entity.TransactionsEntity;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import session.stateful.CustomerSessionBean;
import session.stateful.TransactionSessionBean;

/**
 *
 * @author Dao Thai Duy
 */
@ManagedBean(name = "customerManagerBean")
@SessionScoped
public class CustomerManagerBean {

    @EJB
    private CustomerSessionBean customerSessionBean;
    @EJB
    private TransactionSessionBean transactionSessionBean;
    private Date date1;
    private Date date2;
    private SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    private CustomerEntity selectedCustomer;
    private List<TransactionsEntity> transactionList;

    public CustomerManagerBean() {
        this.date1=null;
        this.date2=null;
    }

    public void viewTransaction(){ 
        setSelectedCustomer(customerSessionBean.getCustomerById(Long.valueOf(123)));
        setTransactionList(transactionSessionBean.getTransactionsOfCustomer(selectedCustomer, date1, date2)); 
    }
    public List<CustomerEntity> getCustomers() {
        return getCustomerSessionBean().getAllCustomers();
    }

    public List<String> getCustomerEmails() {
        return getCustomerSessionBean().getAllEmails();
    }

    public CustomerSessionBean getCustomerSessionBean() {
        return customerSessionBean;
    }

    public void setCustomerSessionBean(CustomerSessionBean customerSessionBean) {
        this.customerSessionBean = customerSessionBean;
    }

    public TransactionSessionBean getTransactionSessionBean() {
        return transactionSessionBean;
    }

    public void setTransactionSessionBean(TransactionSessionBean transactionSessionBean) {
        this.transactionSessionBean = transactionSessionBean;
    }

    public Date getDate1() {
        return date1;
    }

    public void setDate1(Date date1) {
        this.date1 = date1;
    }

    public Date getDate2() {
        return date2;
    }

    public void setDate2(Date date2) {
        this.date2 = date2;
    }

    public SimpleDateFormat getSdf() {
        return sdf;
    }

    public void setSdf(SimpleDateFormat sdf) {
        this.sdf = sdf;
    }

    public CustomerEntity getSelectedCustomer() {
        return selectedCustomer;
    }

    public void setSelectedCustomer(CustomerEntity selectedCustomer) {
        this.selectedCustomer = selectedCustomer;
    }

    public List<TransactionsEntity> getTransactionList() {
        return transactionList;
    }

    public void setTransactionList(List<TransactionsEntity> transactionList) {
        this.transactionList = transactionList;
    }

}
